package com.c6906.vdam.das.model.entity;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.c6906.vdam.das.model.dto.FunctionalAreaDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.UUID;

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("EW_VEHICLE_DETAIL")
public class EWVehicleDetail {
    @TableId
    String ewCode;
    Integer ewType;
    Integer year;
    Integer month;
    String regionCode;
    String regionName;
    Long vehiclesCode;
    String vehPlateNum;
    Long ownUnitId;
    String ownUnitName;
    Long useUnitId;
    String useUnitName;
    String plateColorName;
    String vehTypeName;
    String vehPropName;
    String brandType;
    String vehColorName;
    String useCode;
    Date startTime;
    Date endTime;
    Double startMileage;
    Double endMileage;
    String startLocation;
    String endLocation;
    Double startLocLng;
    Double startLocLat;
    Double endLocLng;
    Double endLocLat;
    Long duration;
    Double mileage;
    Long areaCode;
    String areaId;
    String areaName;
    String terminalSn;
    String simCard;
    Integer warningLevel;
    String ewRemark;
    Long createUser;
    String createUserName;
    Date createTime;
    Long updateUser;
    String updateUserName;
    Date updateTime;
    Integer status;
    Integer isDeleted;
    /**
     * 逻辑字段start
     */
    @TableField(exist = false)
    Long fenceId;
    @TableField(exist = false)
    Date firstInAreaTime;
    @TableField(exist = false)
    Date firstParkAreaTime;
    @TableField(exist = false)
    Date firstOutAreaTime;
    @TableField(exist = false)
    Date firstParkOutAreaTime;
    // 是否已生效预警 0未生效,1已生效
    @TableField(exist = false)
    Integer statusFlag;
//    Long ewId;

    /**
     * 逻辑字段end
     */
    public EWVehicleDetail(FunctionalAreaDTO area, TerminalBusinessInfo terminalBusinessInfo) {
        this.ewCode = UUID.randomUUID().toString().replace("-", "");
        this.ewType = 9;
        this.year = LocalDateTime.now().getYear();
        this.month = LocalDateTime.now().getMonthValue();
        this.regionCode = terminalBusinessInfo.getRegionCode();
        this.regionName = terminalBusinessInfo.getRegionName();
        this.vehiclesCode = Convert.toLong(terminalBusinessInfo.getVehiclesCode());
        this.vehPlateNum = terminalBusinessInfo.getVehPlateNum();
        this.ownUnitId = Convert.toLong(terminalBusinessInfo.getOwnUnitId());
        this.ownUnitName = terminalBusinessInfo.getOwnUnitName();
        this.useUnitId = Convert.toLong(terminalBusinessInfo.getUseUnitId());
        this.useUnitName = terminalBusinessInfo.getUseUnitName();
        this.plateColorName = terminalBusinessInfo.getPlateColorName();
        this.vehTypeName = terminalBusinessInfo.getVehTypeName();
        this.vehPropName = terminalBusinessInfo.getVehPropName();
        this.brandType = terminalBusinessInfo.getBrandType();
        this.vehColorName = terminalBusinessInfo.getVehColorName();
        this.areaCode = Convert.toLong(area.getAreaCode());
        this.areaId = area.getId().toString();
        this.areaName = area.getAreaName();
        this.terminalSn = terminalBusinessInfo.getTerminalSn();
        this.fenceId = area.getId();
        this.warningLevel = Convert.toInt(area.getWarningLevel());
        if (area.getFuncTypeId().equals("9")) {
            this.ewRemark = "风景名胜区停留超30分钟。";
        } else {
            this.ewRemark = "特定场所停留超30分钟。";
        }
        this.status = 1;
        this.isDeleted = 0;
        this.statusFlag = 0;
        this.simCard = terminalBusinessInfo.getSimCard();
    }
}
